﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Data.Objects;
using System.Linq;
using System.Windows;
using System.Xml.Linq;
using Telerik.Windows.Controls.Scheduler;
using Telerik.Windows.Controls.Scheduler.ICalendar;

namespace Centrica.TaskManager.Task.Calendar
{
    public class TaskSchedulerProvider : SchedulerProviderBase
    {

        private bool isEditingThroughScheduler;


        public override IEnumerable GetAppointments()
        {

            TaskAppointment appointMent;
            ObservableCollection<TaskAppointment> appointmentsCollection = new ObservableCollection<TaskAppointment>();

            DateTime startTime = scheduler.VisibleRangeStart;
            DateTime endTime = scheduler.VisibleRangeEnd;

            ObjectParameter[] objParams = new ObjectParameter[2];

            objParams[0] = new ObjectParameter("startTime", scheduler.VisibleRangeStart);
            objParams[1] = new ObjectParameter("endTime", scheduler.VisibleRangeEnd);

            ObjectQuery<Data.Task> apptsQuery =
               Data.ContextManager.Context.Task.Where("it.StartDate >= @startTime && it.EndDate <= @endTime", objParams);

            foreach (Data.Task task in apptsQuery)
            {

                appointMent = new TaskAppointment(task);

                appointmentsCollection.Add(appointMent);

            }

            return appointmentsCollection;
        }


        protected override void OnAppointmentEdited(IAppointment appointment)
        {
            base.UpdateAppointments();

        }

    }
}
